<template>
  <div :bordered="false">
    <f-table ref="bankTable" rowKey="bankId" :columns="columns" :operator="operator" :params="queryParam" :api="api.bib" :autoLoad="false" :showPagination="false" :multiple="false">
         <span slot="bankState" slot-scope="text, record, index">
          <a-switch v-model="record.bankState==1" checkedChildren="启用" unCheckedChildren="禁用" @change="(checked) => setBankState(checked,record)"/>
        </span>
<!--      <span slot="bankType" slot-scope="text, record, index">-->
<!--            <a-tag color="#87d068" v-if="text==1">税金账户</a-tag>-->
<!--            <a-tag color="#108ee9" v-if="text==2">返款账户</a-tag>-->
<!--      </span>-->
      <span slot="action" slot-scope="text, record">
          <template>
            <a @click="editBank(record)">编辑</a>
            <a-divider type="vertical"/>
          </template>
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item v-if="$auth('table.delete')">
                <a href="javascript:;" @click="$refs.bankTable.del(record)">删除</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
    </f-table>
    <a-modal title="添加收款人" :visible="bankModal" width="600px" @cancel="handleCancel" @ok="handleSubmit">
      <f-form ref="form" :action="api.bib" :form-key="this.formItem.bankId">
        <f-form-item label="账户类型" name="bankType" type="radio" dataType="number" :data="api.bib.bankType" :required="true" :value="formItem.bankType"/>
        <f-form-item label="银行名称" name="bankName" :required="true" :value="formItem.bankName"/>
        <f-form-item label="银行卡号" name="bankNo" :required="true" :value="formItem.bankNo"/>
        <f-form-item label="收款人" name="linkMan" :required="true" :value="formItem.linkMan"/>
        <f-form-item label="联系方式" name="linkTel" :required="true" :value="formItem.linkTel"/>
        <f-form-item label="备注" name="remark" :value="formItem.remark"/>
      </f-form>
    </a-modal>
  </div>
</template>

<script>
  import api from './js/api'

  export default {
    name: 'InvoiceUnitBank',
    components: {},
    data() {
      let me = this
      //操作按钮
      let operator = []
      operator.push({
        name: '添加',
        icon: 'plus',
        that: this,
        handler: (table) => {
          this.bankModal = true
        }
      })
      return {
        api: Object.assign(api, this.api),
        //列表初始化查询参数
        queryParam: {},
        bankModal: false,
        formItem: {
          bankId: '',
          bankName: '',
          linkMan: '',
          linkTel: '',
          bankNo: '',
          remark: ''
        },
        // 表头
        columns: [
          {
            title: '#',
            width: '60',
            align: 'center',
            customRender: (text, record, index) => index + 1
          },
          {
            title: '银行名称',
            align: 'center',
            dataIndex: 'bankName'
          },
          {
            title: '卡号',
            align: 'center',
            dataIndex: 'bankNo'
          },
          {
            title: '账户类型',
            align: 'center',
            dataIndex: 'bankType',
            scopedSlots: { customRender: 'bankType' }
          },
          {
            title: '收款人',
            align: 'center',
            dataIndex: 'linkMan'
          },
          {
            title: '联系方式',
            align: 'center',
            dataIndex: 'linkTel'
          },
          {
            title: '状态',
            align: 'center',
            dataIndex: 'bankState',
            scopedSlots: { customRender: 'bankState' }
          },
          {
            title: '备注',
            align: 'center',
            dataIndex: 'remark'
          },
          {
            title: '操作',
            align: 'center',
            scopedSlots: { customRender: 'action' }
          }
        ],
        operator: operator
      }
    },
    created() {
    },
    methods: {
      setData(data) {
        if (data && data.invoiceUnitId) {
          this.queryParam.invoiceUnitId = data.invoiceUnitId
          this.$refs['bankTable'].refresh(false)
        }
      },
      //设置状态
      setBankState(check, record) {
        this.http.post(this, {
          url: this.api.bib.setBankState,
          data: {
            ids: record.bankId,
            bankState: Number(check)
          },
          success(me, data) {
            record.bankState = data
          }
        })
      },
      editBank(bank) {
        this.formItem = bank
        this.bankModal = true
      },
      handleSubmit() {
        this.$refs.form.submit({ invoiceUnitId: this.queryParam.invoiceUnitId }, this.handleCancel)
      },
      handleCancel() {
        this.bankModal = false
      }
    }
  }
</script>